﻿using System.Web.Mvc;
using qlqa.Delegate.FoodDelegate;
using qlqa.Delegate.ThucDonDelegate;
using qlqa.Models.Form.OrderForm;
using qlqa.Models.Form.ThucDonForm;
using qlqa.Models.LinQ;
using Webdiyer.WebControls.Mvc;


namespace qlqa.Controllers
{
    public class ThucDonController : Controller
    {
        //
        // GET: /Menu/

        ThucDonDelegate _thucDonDelegate = new ThucDonDelegate();
        FoodDelegate _foodDelegate = new FoodDelegate();
        
        public ActionResult QuanLyThucDon()
        {
            return View();
        }

        public ActionResult ListThucDon(string timKiem,int? pageNumber)
        {
            var form = new ThucDonForm();
            var listThucDon = _thucDonDelegate.GetDanhSachThucDon(timKiem);
            form.DanhSachthucDon = new PagedList<tb_ThucDon>(listThucDon, pageNumber ?? 1,10);
            return View(form);
        }

        public bool TaoThucDon(tb_ThucDon thucDon)
        {
            var ketQua = _thucDonDelegate.TaoThucDon(thucDon);
            return ketQua;
        }

        public bool CapNhatThucDon(tb_ThucDon thucDon)
        {
            var ketQua = _thucDonDelegate.CapNhatThucDon(thucDon);
            return ketQua;
        }

        public bool XoaThucDon(int thucDonId)
        {
            var ketQua = _thucDonDelegate.XoaThucDon(thucDonId);
            return ketQua;
        }


        public JsonResult GetThongTinThucDon(int idThucDon)
        {
            return Json(_thucDonDelegate.GetThongTinThucDon(idThucDon));
        }

        [HttpPost]
        public JsonResult AutoCompleteMonAn(string term)
        {
            var result = _thucDonDelegate.TimKiemMonAn(term);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult GetListMonAn()
        {
            var form = new OrderForm();
            form.ListMonAn = _foodDelegate.GetFoodByType(null,null);
            form.GetOrSearch = true;
            return PartialView("~/Views/Table/MonAnAjax.ascx",form);
        }

        [HttpPost]
        public ActionResult TimKiemMonAn(string value)
        {
            var form = new OrderForm();
            form.ListMonAn = string.IsNullOrEmpty(value.Trim()) ? _foodDelegate.GetFoodByType(null,null) : _thucDonDelegate.TimKiemMonAn(value);
            form.GetOrSearch = false;

            return PartialView("~/Views/Table/MonAnAjax.ascx", form);
        }
    }
}
